home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11560 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  988 b 

  1. Path: ix.netcom.com!netnews
  2. From: jlilley@ix.netcom.com (John Lilley)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Explicit copy constructor calls illegal?
  5. Date: 15 Mar 1996 02:31:11 GMT
  6. Organization: Netcom
  7. Distribution: world
  8. Message-ID: <4iakpf$3s0@ixnews3.ix.netcom.com>
  9. References: <4i9tp8$fgt@reznor.larc.nasa.gov>
  10. NNTP-Posting-Host: den-co10-19.ix.netcom.com
  11. Mime-Version: 1.0
  12. Content-Type: Text/Plain; charset=US-ASCII
  13. X-NETCOM-Date: Thu Mar 14  6:31:11 PM PST 1996
  14. X-Newsreader: WinVN 0.99.7
  15.  
  16. >Why can I not make an explicit call to a copy constructor from a class
  17. >member function?  To define my terminology, the copy constructor is the
  18. >function:
  19. >                MyClass(const MyClass&)
  20.  
  21. Calling any constructor explicitly is not a good idea except in
  22. rare cases.  If what you are trying to do is centralize basic
  23. copying, then you can define and call operator=():
  24.  
  25.     MyClass& operator=(const MyClass& rhs)
  26.     {
  27.         if (this != &rhs)
  28.         {
  29.             ... copy members here...
  30.         }
  31.     }
  32.  
  33. john lilley
  34.  
  35.